﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>
    <link href="../CSS/Style1.css" rel="stylesheet" type="text/css" />
    <link href="../CSS/style4.css" rel="stylesheet" type="text/css" />
    <script src="../Scripts/jquery-1.4.1-vsdoc.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.pager.js" type="text/javascript"></script>
    <script src="../Scripts/jquery.showModalDialog.js" type="text/javascript"></script>
    <script type="text/javascript">
        function showEdit() {
            //参数：在弹出窗体使用window.dialogArguments获取
            //returnValue：为弹出窗体的返回值，在弹出窗体设置window.returnValue
            //var returnValue = window.showModalDialog("AddSale.htm?data=" + Math.random(), "参数", "dialogWidth:600px;dialogHeight:300px;help:no");
            $.showModalDialog("AddSale.htm", null, 600, 300, function (r) {
                //判断有没有添加成功
                if (r) {
                    //添加成功，刷新列表
                    reloadList();
                }
            });
        }
        //将“/Date(1420646400000)/”转为“2015-01-08”
        function date2str(date) {
            //null判断
            if (date == null) return "";
            //去掉左右的斜杠
            date = date.replace(/\//g, "");
            //将其转为一个日期对象
            eval("var d = new " + date + ";");
            //返回最终结果
            return d.getFullYear() + "年" + (d.getMonth() + 1) + "月" + d.getDate() + "日";
        };
        function Load() {
            $(".dataTable tr:gt(0)").live("click", function () {
                $(".dataTable tr:gt(0)").css("background-color", "white");
                $(this).css("background-color", "orange");
                $(".dataDiv div:first").css("background-image", "url(../images/bg.gif)");
                $(".dataDiv div:last").css("background-image", "url()");
            });
        }
        //进行分页
        $(function () {
            Load();
            reloadList();
        });
        //刷新
        function reloadList() {
            document.getElementById("pageDiv").innerHTML = "";
            //注册分页器控件
            $("#pageDiv").empty().pager2("SaleChanceWebService.asmx/paging", {}, function (data) {
                //展示查询的结果
                $("#headDiv tr:gt(0)").remove();
                var tb1 = $("#headDiv").get(0);
                for (var i = 0; i < data.length; i++) {
                    var tr = tb1.insertRow(-1);
                    tr.insertCell(-1).innerHTML = data[i].ChanName || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanTitle || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanLinkMan || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanLinkTel || "";
                    tr.insertCell(-1).innerHTML = date2str(data[i].ChanCreateDate) || "";
                    tr.insertCell(-1).innerHTML = "<img title='修改' src='../images/33.gif' onclick='Edit(" + data[i].ChanID + ");' />&nbsp;&nbsp;<img title='删除' src='../images/11.gif' onclick='Delete(" + data[i].ChanID + ");' />";
                }
            });
        };
        //修改销售机会表
        function Edit(id) {
            //弹出修改窗体
            $.showModalDialog("EditSale.htm", { id: id }, 600, 300, function (r) {
                //判断有没有修改成功
                if (r) {
                    //修改成功，刷新列表
                    reloadList();
                }
            });
        };
        //删除销售机会表
        function Delete(id) {
            //询问
            if (!confirm("确认删除吗？")) return;
            $.ajax({
                url: "SaleChanceWebService.asmx/DeleteChances",
                type: "post",
                data: JSON.stringify({ id: parseInt(id) }),
                dataType: "json",
                contentType: "application/json",
                success: function (obj) {
                    alert(obj.d ? "删除成功" : "删除失败");
                    reloadList();
                }, error: function (xmlhttp) {
                    alert("错误：" + xmlhttp.responseText);
                }
            });
        };
        function Cha() {
            var sta = {
                action: "select",
                ChanName: $("#txtChanName").val(),
                ChanLinkMan: $("#txtChanLinkMan").val(),
                ChanCreateMan: $("#txtChanCreateMan").val(),
                ChanDueMan: $("#txtChanDueMan").val()
            };

            //注册分页器控件
            $("#pageDiv").empty().pager("SaleAllot.ashx", sta, function (data) {
                //展示查询的结果
                $("#headDiv tr:gt(0)").remove();
                var tb1 = $("#headDiv").get(0);
                for (var i = 0; i < data.length; i++) {
                    var tr = tb1.insertRow(-1);
                    tr.insertCell(-1).innerHTML = data[i].ChanName || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanTitle || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanLinkMan || "";
                    tr.insertCell(-1).innerHTML = data[i].ChanLinkTel || "";
                    tr.insertCell(-1).innerHTML = date2str(data[i].ChanCreateDate) || "";
                    tr.insertCell(-1).innerHTML = "<label style='text-align:center'><img title='修改' src='../images/33.gif' onclick='Edit(" + data[i].ChanID + ");' />&nbsp;&nbsp;<img title='删除' src='../images/11.gif' onclick='Delete(" + data[i].ChanID + ");' /></label>"
                }
            });

        }

    </script>
</head>
<body>
<div id="desDiv">
    <span>销售机会管理</span><br />
    创建和维护销售机会
</div>
<table class="tableEdit">
    <tr>
        <th>客户名称：</th>
        <td><input type="text" id="txtChanName" style="color:blue;width:130px" /></td>
        <th>联系人：</th>
        <td><input type="text"  id="txtChanLinkMan" style="color:blue;width:130px" /></td>
         <th>创建人：</th>
        <td><input type="text"  id="txtChanCreateMan" style="color:blue;width:130px" /></td>
        <th>指派人：</th>
        <td><input type="text"  id="txtChanDueMan" style="color:blue;width:130px" /></td>
    </tr>
    <tfoot>
        <tr>
            <td colspan="8"><input type="button" value="查询" onclick="Cha();" /></td>
        </tr>
    </tfoot>
</table>
<br />
<div id="dataDiv">

    <div id="headDi">
        <img src="../images/22.gif" />&nbsp;&nbsp;<a href="javascript:showEdit()">新建</a>
    </div>
        <table class="dataTable" id="headDiv">
        <tr align="center">
            <td align="center">客户名称</td>
            <td align="center">概要</td>
            <td align="center">联系人</td>
            <td align="center">联系电话</td>
            <td align="center">创建时间</td>
            <td align="center">操作</td>
            
        </tr>
        
    </table>

    <div id="pageDiv">
    </div>
</div>
</body>
</html>
